<template>
	<view>
		<view class="cont" v-for="(k,m) in typeList" :key="m">
			<view class="navs" v-if="k.type == 'checkbox'">
				<view class="title">{{k.title}}</view>
				<label class="uniFlex box" v-for="(item, index) in k.items" :key="index">
					<view>
						<checkbox disabled :checked="item.checked" />
					</view>
					<view>{{item.name}}</view>
				</label>
			</view>
			<view class="navs" v-if="k.type == 'radio'">
				<view class="title">{{k.title}}</view>
				<label class="uniFlex box" v-for="(item, index) in k.items" :key="index">
					<view>
						<radio disabled :checked="item.checked" />
					</view>
					<view>{{item.name}}</view>
				</label>
			</view>
			<view class="navs" v-if="k.type == 'text'">
				<view class="title">{{k.title}}</view>
				<view class="uniFlex2">
					<view class="title">问题描述</view>
					<textarea type="text" disabled v-model="k.ck" placeholder="请输入" placeholder-class="pcs2"></textarea>
				</view>
			</view>
		</view>
		<view class="btnStyle" @click="back">立即返回</view>
		<view style="height: 50upx;"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				typeList: [],
			}
		},
		onLoad(options) {
			this.typeList = JSON.parse(JSON.parse(options.query).items)
			this.typeList.forEach(item => {
				if (item.type == 'checkbox') {
					let items = []
					for (let i = 0; i < item.items.length; i++) {
						let str = {}
						if (this.isInArray(item.ck, i)) {
							str = {
								checked: true,
								name: item.items[i],
								value: item.id
							}
						} else {
							str = {
								checked: false,
								name: item.items[i],
								value: item.id
							}
						}
						items.push(str)
					}
					item.items = items
				} else if (item.type == 'radio') {
					let items = []
					for (let i = 0; i < item.items.length; i++) {
						let str = {}
						if (item.ck[0] == i) {
							str = {
								checked: true,
								name: item.items[i],
								value: item.id
							}
						} else {
							str = {
								checked: false,
								name: item.items[i],
								value: item.id
							}
						}
						items.push(str)
					}
					item.items = items
				} else {
					item.items = ''
				}
			})
		},
		methods: {
			isInArray(arr, value) {
				for (var i = 0; i < arr.length; i++) {
					if (value === arr[i]) {
						return true;
					}
				}
				return false;
			},
			
			back(){
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background: #f8f8f8;
	}

	::v-deep uni-checkbox .uni-checkbox-input.uni-checkbox-input-disabled:before {
		color: #007AFF;
	}


	.cont {
		.navs {
			background: #ffffff;
			padding: 30upx;
			margin-bottom: 30upx;

			.title {
				margin-bottom: 20upx;
				color: #000;
				font-weight: bold;
			}

			.box {
				margin: 20upx 0;
			}

			.uniFlex2 {
				.title {
					line-height: 40px;
					width: 140upx;
					font-size: 30upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #414141;
					margin-right: 40upx;
				}

				textarea {
					flex: 1;
					padding: 20upx 0;
				}
			}
		}
	}

	.btnStyle {
		margin-top: 50upx;
	}
</style>
